function F = firmN(prc_vec,nu,mc,a,b,f_ptr,par_beta)

%
% This function returns vintage(f_ptr) profit-maximizing price 
% given all other prices
%
% algorithm: derivative of profit w.r.t price crosses zero at one spot.  
% Profits are single-peaked (see Shaked-Sutton econometrica), so there
% is one price at which the FONC is zero (holding all other vintage prices
% constant). Use bisection to find that zero-point
%

global tol2 

    % boundaries for price.  
    plow = mc(f_ptr);   % price must be above marginal cost
    phigh= b;           % price must be below highest income
    
    pdiff=tol2+10;
    while pdiff>tol2
        prc_vec(f_ptr) = (plow+phigh)/2;
        % returns all vintages demand given prices
        dmd = demand(prc_vec,nu,a,b,par_beta);
        
        % does firm(f_ptr) have positive market share?
        if(dmd(f_ptr)>0)
            
            % active vintages neighboring f_ptr
            vtg = find(dmd>0);
            low_b=min(vtg); 
            high_b=max(vtg);
            for i=1:length(vtg)
                tmp = f_ptr - vtg(i);
                if(tmp>0)
                    low_b = max(low_b,vtg(i));
                end
                if(tmp<0)
                    high_b = min(high_b,vtg(i));
                end
            end
%            disp('low, actual, high vintages');
%            disp([low_b f_ptr high_b]); pause

            % if this vintage is the only vintage sold - raise price
            if (f_ptr==low_b && f_ptr==high_b)
                fonc = 1;
            % if there are two or more vintages sold
            else               
                % computationally computing change in demand
                prc_tmp = prc_vec;
                dev = prc_vec(f_ptr)*0.01;
                prc_tmp(f_ptr) = prc_vec(f_ptr)+dev*0.5;
                dmd_low = demand(prc_tmp,nu,a,b,par_beta);
                prc_tmp(f_ptr) = prc_vec(f_ptr)-dev*0.5;
                dmd_hgh = demand(prc_tmp,nu,a,b,par_beta);
                chg_dem = (dmd_hgh(f_ptr) - dmd_low(f_ptr))/dev;
                % First order necessary condition                
                fonc = dmd(f_ptr) - (prc_vec(f_ptr)-mc(f_ptr))*(chg_dem);
            end
            
        % if vintage(f_ptr) has no market share -- lower price
        else
            fonc = -1;
        end
       
        % updating guess of profit-maximizing price
        if (fonc<0)
            phigh = prc_vec(f_ptr);
        else
            plow = prc_vec(f_ptr);
        end
        pdiff = phigh-plow;
    end
 %     [pdiff, fonc, prc_vec(f_ptr)], pause
    F = prc_vec(f_ptr);
    
        
